﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace Phoenix.Xna.Framework.Graphics
{
    public class ParameterBindingCollection : List<ParameterBinding>
    {
        private Effect _effect;

        public Effect Effect
        {
            get { return _effect; }
            set
            {
                _effect = value;

                foreach (ParameterBinding b in this)
                {
                    b.Effect = _effect;
                }
            }
        }

        public ParameterBinding this[string id]
        {
            get
            {
                return FirstOf(id);
            }
            set
            {
                ParameterBinding b = FirstOf(id);

                if (b != null)
                {
                    b = value;
                }

                // TODO : add exception message
                throw new IndexOutOfRangeException();
            }
        }

        public bool Contains(string id)
        {
            foreach (ValueBinding b in this)
            {
                if (string.Compare(b.ID, id) == 0)
                {
                    return true;
                }
            }

            return false;
        }

        public ParameterBinding FirstOf(string id)
        {
            foreach (ParameterBinding b in this)
            {
                if (string.Compare(b.ID, id) == 0)
                {
                    return b;
                }
            }

            return null;
        }

        public void Load()
        {
            foreach (ParameterBinding b in this)
            {
                b.SetParameter();
            }
        }

        public void LoadContent()
        {
            foreach(ParameterBinding b in this)
            {
                b.LoadContent();
            }
        }
    }
}
